home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 December / PCWDEC06.iso / Software / Trial / Paint Shop Pro XI / Data1.cab / _076314D25436496BAB6CD45BE6DB4598 < prev    next >
Encoding:
Text File  |  2006-08-04  |  1.7 KB  |  42 lines

  1. from PSPApp import *
  2. import PSPUtils
  3.  
  4. def ScriptProperties():
  5.     return {
  6.         'Author': u'Corel Corporation',
  7.         'Copyright': u'Copyright (c) 2002-2006 Corel Corporation. All rights reserved.',
  8.         'Description': "Center the active layer on the canvas",
  9.         'Host': u'Paint Shop Pro',
  10.         'Host Version': u'8.00'
  11.         }
  12.  
  13. def Do(Environment):
  14.     # we need a document for this to work
  15.     if PSPUtils.RequireADoc( Environment ) == App.Constants.Boolean.false:
  16.         return
  17.  
  18.      # need the canvas size, the layer size and the layer position
  19.     CanvasSize = App.TargetDocument.Size
  20.     LayerInfo = App.Do( Environment, 'ReturnLayerProperties' )
  21.     # LayerRect comes back as a tuple of the from ( (x,y), dx, dy )
  22.     # we want to work with a size tuple and a position tuple, so rearrange it.
  23.     if len(LayerInfo['LayerRect']) == 2:
  24.         LayerSize = (LayerInfo[ 'LayerRect' ][1], LayerInfo[ 'LayerRect' ][1] )
  25.     else:
  26.         LayerSize = (LayerInfo[ 'LayerRect' ][1], LayerInfo[ 'LayerRect' ][2] )
  27.     LayerPos =  LayerInfo[ 'LayerRect' ][0]
  28.     
  29.     # now compute how far to move the layer to get it centered
  30.     DesiredPos = ( (CanvasSize[0] - LayerSize[0]) / 2, (CanvasSize[1] - LayerSize[1]) / 2 )
  31.     Offset = ( DesiredPos[0] - LayerPos[0], DesiredPos[1] - LayerPos[1] )
  32.     App.Do( Environment, 'Mover', {
  33.             'Offset': Offset, 
  34.             'Object': App.Constants.LayerOrSelection.Layer, 
  35.             'SelectPoint': None,
  36.             'GeneralSettings': {
  37.                 'ExecutionMode': App.Constants.ExecutionMode.Default, 
  38.                 'AutoActionMode': App.Constants.AutoActionMode.Match
  39.                 }
  40.             })
  41.  
  42.